package controllers;

import models.IdeaDeveloper;
import models.OrganizationLead;
import models.Organizer;

public class Security extends Secure.Security {

	static IdeaDeveloper user = IdeaDeveloper.find("username = ?",
			Security.connected()).first();

	/**
	 * the method checks if there is a user with the enterd username&password
	 * and if not the user is not authincated to enter the page
	 */

	static boolean authenticate(String username, String password) {
		IdeaDeveloper user = IdeaDeveloper.find("username=? ", username)
				.first();
		return user != null && user.password.equals(password)
				&& !user.deactivated;
	}

	/**
	 * this method returns the id of the conncted user
	 * 
	 * @author mohamed tarek
	 * 
	 * @param it gets the connected username
	 * 
	 * @output the userid of type Long
	 */
	static Long userid() {
		String username = Security.connected();
		IdeaDeveloper conn = IdeaDeveloper.find("username = ?", username)
				.first();
		return conn.id;

	}

	// static boolean check(String profile) {
	// IdeaDeveloper user = IdeaDeveloper.find("username = ?",
	// connected()).first();
	// if () {
	// return user.admin;
	// }
	// else {
	// return false;
	// }
	// }

	public static boolean isOrganizationLead() {
		return OrganizationLead.find("ideaDeveloper=?", user).first() != null;

	}

	public static boolean isOrganizer() {

		return Organizer.find("ideaDeveloper=?", user).first() != null;

	}

}
